<template>
	<view>
		<uni-search-bar style="background-color: #fff;" placeholder="请输入用户名称进行查询" @confirm="getDataList" v-model="queryParam.Keyword"
			@cancel="cancel">
		</uni-search-bar>
		<uni-list>
			<uni-list-item v-for="item in data" :key="item.Id" :title="item.RealName" :note="item.UserPhone"
				:thumb="item.UserAvatarURL||'/static/logo.png'" thumb-size="lg">
				<template v-slot:footer>
					<uni-icons @click="del([item.Id])" type="trash" color="red" size="20"></uni-icons>
				</template>
			</uni-list-item>
		</uni-list>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: [],
				pagination: {
					PageIndex: 1,
					PageRows: 30,
					SortField: "CreateTime",
					SortType: "desc",
				},
				total: 0,
				queryParam: {
					"Condition": "cCusName",
					"Keyword": "",
					"SupplieId": "",
				},
			}
		},
		onNavigationBarButtonTap(e) {
			console.log(e);
			uni.navigateTo({
				url: '/pages/Information/page/subaccount/subaccountForm'
			})
		},
		onLoad() {
			this.queryParam.SupplieId = uni.getStorageSync('CompanyInfo').Id
		},
		onShow() {
			this.pagination.PageIndex = 1
			this.getDataList()
		},
		onReachBottom() {
			if (this.data.length >= this.total) return
			this.pagination.PageIndex++
			uni.showLoading()
			this.$http('post', '/Base_Manage/Base_User/GetDataList', {
					...this.pagination,
					Search: this.queryParam
				})
				.then(res => {
					uni.hideLoading()
					if (res.Success) {
						this.data = this.data.concat(res.Data)
						this.total = res.Total
					} else uni.showToast({
						icon: 'none',
						title: res.Msg
					})
				})
		},
		methods: {
			getDataList() {
				uni.showLoading()
				this.pagination.PageIndex = 1
				this.$http('post', '/Base_Manage/Base_User/GetDataList', {
						...this.pagination,
						Search: this.queryParam
					})
					.then(res => {
						uni.hideLoading()
						if (res.Success) {
							this.data = res.Data
							this.total = res.Total
						} else uni.showToast({
							icon: 'none',
							title: res.Msg
						})
						console.log(this.total);
					})
			},
			del(arr) {
				uni.showModal({
					title: '提示',
					content: '此操作将删除当前用户,确认继续吗?',
					success: (val) => {
						if (val.cancel) return
						this.$http('post', '/Base_Manage/Base_User/DeleteData', arr).then(res => {
							if (!res.Success) return this.$api.msg(res.Msg)
							this.$api.msg('操作成功')
							this.getDataList()
						})
					}
				})

			},
			cancel() {
				this.queryParam.Keyword = ''
				this.getDataList()
			}
		}
	}
</script>

<style>

</style>